<?php
/**
 * 文章管理
 * Created by PhpStorm.
 * User: andy
 * Date: 2019/8/29
 * Time: 下午6:42
 */
namespace app\common\model;

use think\Model;

class BankModel extends Model
{
    const SHOW_STATUS=1; //显示
    const HIDE_STATUS=0; //不显示
    const DEL_STATUS=-1; //删除

    protected $autoWriteTimestamp = true;

    protected $pk='bank_id';

    public function user()
    {
        return $this->hasOne('MemberModel','uid','user_id')->field('uid,mobile');
    }


    /**
     * 所有推荐
     * @param array $where
     * @param int $pageSum
     * @return \think\Paginator
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getALL($where=[],$pageSum=0)
    {
        if($pageSum<=0){
            $pageSum=getSystem("pageSUM")?getSystem("pageSUM"):10;
        }

        $list=self::with('user')
            ->where('status','>',self::DEL_STATUS)
            ->where($where)
            ->paginate($pageSum);

        return $list;
    }



    /**
     * 删除
     * @param $id
     * @return array
     */
    public function del($id){

        $au=self::get($id);
        $au->status=-1;
        $au->delete_time=time();

        $status=$au->save();
        if($status){
            return ['status'=>1,'msg'=>'删除成功！'];
        }else{
            return ['status'=>0,'msg'=>'删除失败！'];
        }
    }

}